
/**********************************************************************/
/*
   Title: output.do
   Author: Clotaire Boyer, Robbie Dulin
   Description: Creates tables for FI paper.
*/
/**********************************************************************/


cap log close
local prefix: display %tdCYND td(`c(current_date)')
log using "$log/`prefix'_output", replace text


clear
set more off

** Globals
global output                       "$rundir/04_Output"
global finance_data "$cleaned/finance"
global randomization                "$base/04_ResearchDesign/02 Randomization/1705 Kab Randomization v6 - 8.2 milion, treat most java - FINAL"

  /*----------------------------------------------------*/
         /* Section 1: Table 1, agents, savings, credit */
  /*----------------------------------------------------*/

  est clear
  eststo clear
  qui cd "$output/ster_files/20210226_finance"


  // Loading outputs stored in ster files (SUS Regs)

  local sterfile `prefix'_banking_HH.ster
  estimates describe using "`sterfile'"
  forvalues j=1/`r(nestresults)' {
      estimates describe using "`sterfile'", number(`j')
      local title `r(title)'
      estimates use "`sterfile'", number(`j')
      est store `title'
  }

  // Loading outputs stored in ster files (Agent Reg)

  local sterfile `prefix'_agents.ster
  estimates describe using "`sterfile'"
  forvalues j=1/`r(nestresults)' {
      estimates describe using "`sterfile'", number(`j')
      local title `r(title)'
      estimates use "`sterfile'", number(`j')
      est store `title'
  }

  //  Table 1 and appendix

esttab agentsWagents0IE agentagents0IE savings_accountall0 creditall0   ///
  using "$output/tables/hh_credsavings_all.tex", replace style(tex) ///
  cells(b(fmt(3)) se(par fmt(3)) pvalues(par([ ]) fmt(3))) collabels(none) keep(treated) varlabels(treated "Voucher") ///
  nolines prefoot(\midrule) nonum nomtitle booktabs frag ///
  stats(obs control_mean, label("Observations" "DV Mean (Control)" ) fmt(0 3))

esttab agentsWagents0IE agentagents0IE savings_accountall0 creditall0   ///
    using "$output/tables/hh_credsavings_all.csv", replace ///
    cells(b(fmt(3)) se(par fmt(3)) pvalues(par([ ]) fmt(3))) collabels(none) keep(treated) varlabels(treated "Voucher") ///
    nolines stats(obs control_mean, label("Observations" "DV Mean (Control)") fmt(0 3)) csv

    //  Appendix of Table 1 : All villages

esttab agentsWallIE agentallIE savings_accountallall creditallall  ///
        using "$output/tables/hh_credsavings_all_apx.tex", replace style(tex) ///
        cells(b(fmt(3)) se(par fmt(3)) pvalues(par([ ]) fmt(3))) collabels(none) keep(treated) varlabels(treated "Voucher") ///
        nolines prefoot(\midrule) nonum nomtitle booktabs frag ///
        stats(obs control_mean, label("Observations" "DV Mean (Control)" ) fmt(0 3))


      //  Appendix Table: By beneficiary Status

   * Panel A : PMT less 30

esttab savings_accountpmt300 creditpmt300 ///
    using "$output/tables/hh_credsavings0_pmt30.tex", replace style(tex) ///
    cells(b(fmt(3)) se(par fmt(3)) pvalues(par([ ]) fmt(3))) collabels(none) keep(treated) varlabels(treated "Voucher") ///
    nolines prefoot(\midrule) nonum nomtitle booktabs frag ///
    stats(obs control_mean, label("Observations" "DV Mean (Control)" ) fmt(0 3))

    * Panel B : PMT above 30

esttab  savings_accountabove0 creditabove0    ///
    using "$output/tables/hh_credsavings0_above.tex", replace style(tex) ///
    cells(b(fmt(3)) se(par fmt(3)) pvalues(par([ ]) fmt(3))) collabels(none) keep(treated) varlabels(treated "Voucher") ///
    nolines prefoot(\midrule) nonum nomtitle booktabs frag ///
    stats(obs  control_mean, label("Observations" "DV Mean (Control)" ) fmt(0 3))


  /*----------------------------------------------------*/
          /* Section 2: Business Tables */
  /*----------------------------------------------------*/

  est clear
  eststo clear
  qui cd "$output/ster_files/20210226_finance"



  local sterfile `prefix'_allbusinessespodes.ster
  estimates describe using "`sterfile'"
  forvalues j=1/`r(nestresults)' {
          estimates describe using "`sterfile'", number(`j')
          local title `r(title)'
          estimates use "`sterfile'", number(`j')
          est store `title'
                  }

  * Table 2

      esttab  typej_n0  typege_n0 typef_n0  ///
          using "$output/tables/busi_0.tex", replace style(tex)  ///
          cells(b(fmt(3)) se(par fmt(3)) pvalues(par([ ]) fmt(3))) collabels(none) keep(treated) varlabels(treated "Voucher") ///
          nolines prefoot(\midrule) nonum nomtitle booktabs frag ///
          stats(obs control_mean, label("Observations" "DV Mean (Control)" ) fmt(0 3))

  * Appendix of Table 2: All Villages

      esttab   typej_nfull  typege_nfull typef_nfull  ///
                using "$output/tables/busi_all.tex", compress ///
                replace style(tex) ///
                cells(b(fmt(3)) se(par fmt(3)) pvalues(par([ ]) fmt(3))) collabels(none) keep(treated ) varlabels(treated "Voucher" ) ///
                nolines prefoot(\midrule) nonum nomtitle booktabs frag ///
                stats(obs control_mean, label("Observations" "DV Mean (Control)" ) fmt(0 3))


/*----------------------------------------------------*/
            /* Section: Individual Results */
/*----------------------------------------------------*/

qui cd "$output/ster_files/20210226_finance"
est clear
eststo clear

local sterfile "`prefix'_mar19_ind_sav.ster"
estimates describe using "`sterfile'"
forvalues j=1/`r(nestresults)' {
    estimates describe using "`sterfile'", number(`j')
    local title `r(title)'
    qui estimates use "`sterfile'", number(`j')
    qui est store `title'
}

// SAVINGS

*   Panel A : All Households

esttab savingsallanysex0 savingsallmen0 savingsallwomen0 savingsallanysexfull savingsallmenfull savingsallwomenfull ///
using "$output/tables/savings_ind_all.tex", replace ///
cells(b(fmt(3)) se(par fmt(3)) pvalues(par([ ]) fmt(3))) keep(treated) varlabels(treated "Voucher") ///
booktabs frag collabels(none) nolines nonum mlabels(none) ///
 prefoot(`"\midrule"') postfoot(`"\midrule"') ///
stats(obs  control_mean, label("Observations" "DV Mean (Control)" ) fmt(0 3))


* Panel B : HH with PMT less than 30

esttab savingspmt30anysex0 savingspmt30men0 savingspmt30women0 savingspmt30anysexfull savingspmt30menfull savingspmt30womenfull using ///
"$output/tables/savings_ind_pmt30.tex", replace ///
cells(b(fmt(3)) se(par fmt(3)) pvalues(par([ ]) fmt(3))) keep(treated) varlabels(treated "Voucher") ///
booktabs frag collabels(none) nolines nonum mlabels(none) ///
prefoot(`"\midrule"') postfoot(`"\midrule"') ///
stats(obs  control_mean, label("Observations"  "DV Mean (Control)" ) fmt(0 3))

* Panel C : HH with PMT above 30

esttab savingsaboveanysex0 savingsabovemen0 savingsabovewomen0 savingsaboveanysexfull savingsabovemenfull savingsabovewomenfull using ///
"$output/tables/savings_ind_above.tex", replace ///
cells(b(fmt(3)) se(par fmt(3)) pvalues(par([ ]) fmt(3))) keep(treated) varlabels(treated "Voucher") ///
booktabs frag collabels(none) nolines nonum mlabels(none) ///
prefoot(`"\midrule"') postfoot(`"\midrule"') ///
stats(obs  control_mean, label("Observations"  "DV Mean (Control)" ) fmt(0 3))



/*----------------------------------------------------*/
            /* Section: PKH Receipt */
/*----------------------------------------------------*/

// Loading outputs stored in ster files
local sterfile `prefix'_banking_HH.ster
estimates describe using "`sterfile'"
forvalues j=1/`r(nestresults)' {
    estimates describe using "`sterfile'", number(`j')
    local title `r(title)'
    estimates use "`sterfile'", number(`j')
    est store `title'
}



       * Panel A : All HH

   esttab pkh_receiptall0 pkh_agentall0 phk_other_locationall0  pkh_receiptallall pkh_agentallall phk_other_locationallall  ///
         using "$output/tables/hh_othersocial_full.tex", replace style(tex) ///
         cells(b(fmt(3)) se(par fmt(3)) pvalues(par([ ]) fmt(3))) collabels(none) keep(treated) varlabels(treated "Voucher") ///
         nolines prefoot(\midrule) nonum nomtitle booktabs frag ///
         stats(obs control_mean, label("Observations" "DV Mean (Control)" ) fmt(0 3))

       * Panel B : PMT less 30

   esttab pkh_receiptpmt300 pkh_agentpmt300 phk_other_locationpmt300  pkh_receiptpmt30all pkh_agentpmt30all phk_other_locationpmt30all    ///
         using "$output/tables/hh_othersocial_pmt30.tex", replace style(tex) ///
         cells(b(fmt(3)) se(par fmt(3)) pvalues(par([ ]) fmt(3))) collabels(none) keep(treated) varlabels(treated "Voucher") ///     
         nolines prefoot(\midrule) nonum nomtitle booktabs frag ///
         stats(obs control_mean, label("Observations" "DV Mean (Control)" ) fmt(0 3))

         * Panel C : PMT above 30

   esttab  pkh_receiptabove0 pkh_agentabove0 phk_other_locationabove0  pkh_receiptaboveall pkh_agentaboveall phk_other_locationaboveall  ///
           using "$output/tables/hh_othersocial_above.tex", replace style(tex) ///
           cells(b(fmt(3)) se(par fmt(3)) pvalues(par([ ]) fmt(3))) collabels(none) keep(treated) varlabels(treated "Voucher") ///
           nolines prefoot(\midrule) nonum nomtitle booktabs frag ///
           stats(obs control_mean, label("Observations" "DV Mean (Control)" ) fmt(0 3))




cap log close
// DONE
